# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Alexander Fehr <pizzapunk gmail com>
# Contributor: Andrew Simmons <andrew.simmons@gmail.com>

pkgbase=xarchiver
pkgname=(xarchiver xarchiver-gtk2)
pkgver=0.5.4.21
pkgrel=1
pkgdesc="GTK+ frontend to various command line archivers"
arch=(loong64 x86_64)
url="https://github.com/ib/xarchiver"
license=(GPL)
depends=(gtk2 gtk3)
makedepends=(docbook-xsl intltool xmlto)
optdepends=('arj: ARJ support'
            'binutils: deb support'
            'bzip2: bzip2 support'
            'cpio: RPM support'
            'gzip: gzip support'
            'lha: LHA support'
            'lrzip: lrzip support'
            'lz4: LZ4 support'
            'lzip: lzip support'
            'lzop: LZOP support'
            'p7zip: 7z support'
            'tar: tar support'
            'unarj: ARJ support'
            'unrar: RAR support'
            'unzip: ZIP support'
            'xdg-utils: recognize more file types to open'
            'xz: xz support'
            'zip: ZIP support'
            'zstd: zstd support')
source=(https://github.com/ib/xarchiver/archive/$pkgver/$pkgbase-$pkgver.tar.gz
        xarchiver.appdata.xml)
sha256sums=('65329bff7e901452f3f927d913c47ffca759a36e83e8b82d04fe6945e7393fd4'
            '55f41aa0e5569b446933a34ac0585443fa5bd92f03f47e1fd53daf19905cc97e')

build() {
  # GTK+ 3 version
  [ -d gtk3 ] || cp -r $pkgbase-$pkgver gtk3
  cd gtk3
  ./configure --prefix=/usr --libexecdir=/usr/lib/xfce4
  make

  cd "$srcdir"
  # GTK+ 2 version
  [ -d gtk2 ] || cp -r $pkgbase-$pkgver gtk2
  cd gtk2
  ./configure --prefix=/usr --libexecdir=/usr/lib/xfce4 --enable-gtk2
  make
}

package_xarchiver() {
  depends=(gtk3)

  cd gtk3
  make DESTDIR="$pkgdir" install
  install -Dm644 ../$pkgname.appdata.xml "$pkgdir/usr/share/metainfo/$pkgname.appdata.xml"
}

package_xarchiver-gtk2() {
  pkgdesc+=' (GTK+ 2 version)'
  depends=(gtk2)
  conflicts=(xarchiver)

  cd gtk2
  make DESTDIR="$pkgdir" install

  # Ignore package by AppStream to avoid duplicated IDs
  echo 'X-AppStream-Ignore=true' >> "$pkgdir/usr/share/applications/xarchiver.desktop"
}
